% This is for the case of t1g1,t2g1,t3g1,tntg1,t1g2,...

function [result] = lag_ntng(panel,tindex,gindex,var,nlag)

    ng=length(unique(panel(:,gindex)));
    nt=length(unique(panel(:,tindex)));
    
    temp=panel(:,var);
    temp=reshape(temp,nt,ng);

    result(1:nt,1:ng)=nan;
    result(nlag+1:nt,:)=temp(1:nt-nlag,:);
    result=result(:);

end

